package cyou.breathe.dynamictp.nacos.cloud.example.configuration;

import cyou.breathe.dynamictp.core.executor.support.BlockingQueueTypeEnum;
import cyou.breathe.dynamictp.core.toolkit.ThreadPoolExecutorBuilder;
import cyou.breathe.dynamictp.spring.base.BreatheDynamicTp;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.ThreadPoolExecutor;

/**
 * 动态线程池配置
 * @author: breathe
 * @createTime: 2025-09-15
 */
@Configuration
public class DynamicThreadPoolConfiguration {
    @Bean
    @BreatheDynamicTp
    public ThreadPoolExecutor breatheThreadProducer() {
        return ThreadPoolExecutorBuilder.builder()
                .threadPoolId("breathe-thread-producer")
                .corePoolSize(2)
                .maximumPoolSize(4)
                .keepAliveTime(9999L)
                .workQueueType(BlockingQueueTypeEnum.SYNCHRONOUS_QUEUE)
                .threadFactory("breathe-thread-producer_")
                .rejectedHandler(new ThreadPoolExecutor.CallerRunsPolicy())
                .dynamicPool()
                .build();
    }

    @Bean
    @BreatheDynamicTp
    public ThreadPoolExecutor breatheThreadConsumer() {
        return ThreadPoolExecutorBuilder.builder()
                .threadPoolId("breathe-thread-consumer")
                .corePoolSize(4)
                .maximumPoolSize(6)
                .keepAliveTime(9999L)
                .workQueueType(BlockingQueueTypeEnum.SYNCHRONOUS_QUEUE)
                .threadFactory("breath-thread-consumer_")
                .rejectedHandler(new ThreadPoolExecutor.CallerRunsPolicy())
                .dynamicPool()
                .build();
    }
}
